package com.sgb.zhaocai.view.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sgb.zhaocai.BR;
import com.sgb.zhaocai.R;
import com.sgb.zhaocai.entity.TenderExternalListEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

/**
 * Time:2021/12/20
 * AUTHOR:F_Q
 * Description:
 */
public class WebSiteInvitedAdapter extends BaseRecycleAdapter<TenderExternalListEntity> {

    String fromWheres;

    public WebSiteInvitedAdapter(Context context, List<TenderExternalListEntity> datas, String fromWhere) {
        super(context, R.layout.item_website_invite, datas);
        this.fromWheres = fromWhere;
    }

    @Override
    public void onBindViewHolder(ItemViewHolder holder, @SuppressLint("RecyclerView") int position) {
        super.onBindViewHolder(holder, position);
        TextView again_invite = holder.itemView.findViewById(R.id.again_invite);//再次邀请按钮
        again_invite.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                OnItemStateOperate.OnAgainInviteData(datas.get(position));
            }
        });

        TextView tvCompanyName = holder.itemView.findViewById(R.id.tv_companyName);
        String companyName = datas.get(position).getCompanyName();
        if(TextUtils.isEmpty(companyName)){
            tvCompanyName.setText("无");
        }else{
            tvCompanyName.setText(companyName);
        }
    }

    @Override
    public void convert(ItemViewHolder holder, final TenderExternalListEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        TextView itemStater = holder.itemView.findViewById(R.id.item_stater);//是否已报名
        LinearLayout ll_again_invite = holder.itemView.findViewById(R.id.ll_again_invite);//是否展示再次邀请按钮
        TextView tvkey = holder.itemView.findViewById(R.id.tvkey);//是否已报名
        TextView tv_value = holder.itemView.findViewById(R.id.tv_value);//是否已报名
        switch (fromWheres) {
            case "1":
                tvkey.setText("招标名称：");
                tv_value.setText(entity.getTenderName() + "");
                itemStater.setText(entity.getTenderStateName());
                switch (entity.getTenderState()) {
                    case "9"://招标报名
                        ll_again_invite.setVisibility(View.VISIBLE);
                        itemStater.setBackground(context.getResources().getDrawable(R.drawable.corner_dark_purple_bg));
                        itemStater.setTextColor(context.getResources().getColor(R.color.color_white));
                        break;
                    case "1"://即将招标
                        ll_again_invite.setVisibility(View.GONE);
                        itemStater.setBackground(context.getResources().getDrawable(R.drawable.corner_dark_yellow_bg));
                        itemStater.setTextColor(context.getResources().getColor(R.color.color_white));
                        break;
                    case "2"://正在招标
                        ll_again_invite.setVisibility(View.GONE);
                        itemStater.setBackground(context.getResources().getDrawable(R.drawable.corner_dark_orange_bg));
                        itemStater.setTextColor(context.getResources().getColor(R.color.color_white));
                        break;
                    case "3"://竞标评标
                        ll_again_invite.setVisibility(View.GONE);
                        itemStater.setBackground(context.getResources().getDrawable(R.drawable.corner_dark_green_bg));
                        itemStater.setTextColor(context.getResources().getColor(R.color.color_white));
                        break;
                    case "4"://招标定标
                        ll_again_invite.setVisibility(View.GONE);
                        itemStater.setBackground(context.getResources().getDrawable(R.drawable.corner_dark_gray_bg));
                        itemStater.setTextColor(context.getResources().getColor(R.color.color_white));
                        break;
                    case "5"://废标
                        ll_again_invite.setVisibility(View.GONE);
                        itemStater.setBackground(context.getResources().getDrawable(R.drawable.abolish_bid_outline));
                        itemStater.setTextColor(context.getResources().getColor(R.color.color_tab_three));
                        break;
                    case "7"://流标
                        ll_again_invite.setVisibility(View.GONE);
                        itemStater.setBackground(context.getResources().getDrawable(R.drawable.failure_bid_outline));
                        itemStater.setTextColor(context.getResources().getColor(R.color.color_4D4545));
                        break;
                }
                break;
            case "2":
                tvkey.setText("竞价名称：");
                tv_value.setText(entity.getBidName() + "");
                itemStater.setText(entity.getBidStateName());
                switch (entity.getBidState()){
                    case "2"://竞价中
                        ll_again_invite.setVisibility(View.VISIBLE);
                        itemStater.setBackground(context.getResources().getDrawable(R.drawable.corner_dark_purple_bg));
                        itemStater.setTextColor(context.getResources().getColor(R.color.color_white));
                        break;
                    case "5"://谈判中
                        ll_again_invite.setVisibility(View.GONE);
                        itemStater.setBackground(context.getResources().getDrawable(R.drawable.corner_dark_orange_bg));
                        itemStater.setTextColor(context.getResources().getColor(R.color.color_white));
                        break;
                    case "4"://废标
                    case "3"://已结束
                        ll_again_invite.setVisibility(View.GONE);
                        itemStater.setBackground(context.getResources().getDrawable(R.drawable.abolish_bid_outline));
                        itemStater.setTextColor(context.getResources().getColor(R.color.color_tab_three));
                        break;
                }
                break;
        }

    }

    private OnItemStateOperate OnItemStateOperate;

    public void setOnItemStateOperate(OnItemStateOperate onItemStateOperate) {
        OnItemStateOperate = onItemStateOperate;
    }

    public interface OnItemStateOperate {

        void OnAgainInviteData(TenderExternalListEntity tenderExternalListEntity);
    }
}
